package com.zq.springcloud.controller;

import com.zq.springcloud.entity.Emp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * ================================================
 * 作    者：程志强
 * 邮    箱：cheng.zhiqiang@cesgroup.com.cn
 * 版    本：1.0.0
 * 创建日期：2020/12/31  13:59
 * 修改日期：
 * 描    述：消费者controller
 * 修订历史：
 * ================================================
 */
@RestController
@RequestMapping("/consumer")
public class EmpConsumerController {
    // 提供者的ip+端口
    // private static final String REST_URL_PREFIX = "http://localhost:8001";
    // Ribbon 这里历史应该是一个变量，通过服务名来访问
    private static final String REST_URL_PREFIX = "http://SPRING-CLOUD-PROVIDER-EMP";

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/query/{empId}")
    public Emp getOne(@PathVariable("empId") long empId) {
        return restTemplate.getForObject(REST_URL_PREFIX + "/provider/query-one/" + empId, Emp.class);
    }


    @GetMapping("/query")
    public List<Emp> getAll() {
        return restTemplate.getForObject(REST_URL_PREFIX + "/provider/query-list", List.class);
    }
}
